package org.marsdonne.audits.artemis;

import org.marsdonne.audits.Caught;
import org.marsdonne.audits.ExceptionAuditable;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.core.JmsTemplate;

import javax.annotation.Resource;

public class ExceptionAuditImpl implements ExceptionAuditable {

    @Value("${spring.application.name}")
    private String serviceId;

    @Value("${audits.artemis.channel.caught:channels.audits.caught}")
    private String channel;

    @Resource
    private JmsTemplate auditsJmsTemplate;

    @Override
    public void captured(Caught caught) {
        caught.setServiceId(serviceId);
        auditsJmsTemplate.send(channel, session -> session.createObjectMessage(caught));
    }
}
